( function($) {
	$.previewImg = $.previewImg || {};
	$.previewImg.init = function(selector) {
		
		$(selector).each(function(i,n){
			var url = $(n).attr("url");
			var pWidth = parseInt($(n).attr("pWidth"));
			var pHeight = parseInt($(n).attr("pHeight"));
			
			if(isNaN(pHeight)){
				pHeight = pWidth;
			}
			
			$(n).css({
				"width":pWidth+"px",
				"height":pHeight+"px"
			});
			
			if(url.indexOf("_")==-1){
				var mt = (pHeight-22)/2;
				if(url.length>40){ // 地址小于40可能只是域名，没有图片路径
					var p1 = url.split(".");
					$(n).html("<div style='font-weight:bold; font-size:16px; display:block; text-align:center; color:#999; margin-top:"+mt+"px;'>"+p1[1]+"</div>");
				}else{
					$(n).html("<div style='font-weight:bold; font-size:16px; display:block; text-align:center; color:#999; margin-top:"+mt+"px;'>暂无</div>");
				}
			}else{
				var p1 = url.split("_");
				var p2 = p1[1].split(".");
				var p3 = p2[0].split("x");
				var iw = p3[0];
				var ih = p3[1];
				var ext = p2[1];
				
				var dv = pWidth/pHeight;
				var iv = iw/ih;
				
				var rw = 0;
				var rh = 0;
				var ml = 0;
				
				if(dv>=iv){
					rh = pHeight;
					rw = iw*rh/ih;
					ml = (pWidth-rw)/2;
				}else{
					rw = pWidth;
					rh = ih*rw/iw;
				}
				
				var img = "<a href='"+url+"' target='_blank'>";
				img += "<img src='"+url+"' width='"+rw+"' height='"+rh+"' style='display:inline-block; margin-left:"+ml+"px;' />";
				img += "</a>";
				$(n).html(img);
			}
			
		});
		
	};
	$.previewImg.clearAll = function(){
	};
})(jQuery);